package com.test.proxy.invok;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author RenGaoshuai
 * @date 2024/6/3 15:40
 * @description
 */
public class AddLoggerHandler implements InvocationHandler {

    private Object target;

    public AddLoggerHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //执行前
        System.out.println("日志开始，时间：" + System.currentTimeMillis());

        Object invoke = method.invoke(target, args);

        //执行后
        System.out.println("日志结束，时间：" + System.currentTimeMillis());
        return invoke;
    }
}
